package com.alan.wifishare.app;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @className: UserConfig
 * @describtion: UserConfig
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/26 16:12
 */
public class UserConfig {

    private SharedPreferences configSP = null;
    private final String CONFIGINFO = "UserConfig";
    private final String KEY_USER_ACCOUNT = "user_account";
    private final String KEY_USER_PWD = "user_pwd";
    private final String KEY_USER_FIRST_USE = "user_first_use";
    private final String KEY_DEVICE_SSID = "device_ssid";
    private final String KEY_DEVICE_PWD = "device_pwd";
    private final String KEY_DEVICE_MAC = "device_mac";

    private static UserConfig _instance = null;

    public static UserConfig getInstance(Context context) {
        if(_instance == null){
            _instance = new UserConfig(context);
        }
        return _instance;
    }

    private UserConfig(Context context) {
        configSP = context.getSharedPreferences(CONFIGINFO, Context.MODE_PRIVATE);
    }

    /**
     * 获取用户帐号
     * @return
     */
    public String getUserAccount(){
        return configSP.getString(KEY_USER_ACCOUNT, null);
    }

    /**
     * 保存用户帐号
     * @param userAccount
     */
    public void setUserAccount(String userAccount){
        SharedPreferences.Editor editor = configSP.edit();
        editor.putString(KEY_USER_ACCOUNT, userAccount);
        editor.commit();
    }

    /**
     * 获取用户密码
     * @return
     */
    public String getUserPwd(){
        return configSP.getString(KEY_USER_PWD, null);
    }

    /**
     * 保存用户帐号
     * @param userPwd
     */
    public void setUserPwd(String userPwd){
        SharedPreferences.Editor editor = configSP.edit();
        editor.putString(KEY_USER_PWD, userPwd);
        editor.commit();
    }

    /**
     * 保存已连接的设备的SSID
     * @param ssid 设备的SSID
     */
    public void setDeviceSSID(String ssid) {
        SharedPreferences.Editor editor = configSP.edit();
        editor.putString(KEY_DEVICE_SSID, ssid);
        editor.commit();
    }

    /**
     * 设置第一次使用标志
     * @param isFirstUse
     */
    public void setIsFirstUse(boolean isFirstUse){
        SharedPreferences.Editor editor = configSP.edit();
        editor.putBoolean(KEY_USER_FIRST_USE, isFirstUse);
        editor.commit();
    }

    /**
     * 是否是第一次使用
     * @return
     */
    public boolean isFirstUse(){
        return configSP.getBoolean(KEY_USER_FIRST_USE, true);
    }

    /**
     * 获取已连接设备的SSID
     * @return
     */
    public String getDeviceSSID() {
        return configSP.getString(KEY_DEVICE_SSID, null);
    }

    /**
     * 保存设备的wifi连接密码
     * @param password
     */
    public void setDevicePwd(String password) {
        SharedPreferences.Editor editor = configSP.edit();
        editor.putString(KEY_DEVICE_PWD, password);
        editor.commit();
    }

    /**
     * 获取设备wifi的连接密码
     * @return
     */
    public String getDevicePwd() {
        return configSP.getString(KEY_DEVICE_PWD, null);
    }

    /**
     * 保存设备的mac地址
     * @param mac
     */
    public void setDeviceMac(String mac) {
        SharedPreferences.Editor editor = configSP.edit();
        editor.putString(KEY_DEVICE_MAC, mac);
        editor.commit();
    }

    /**
     * 获取设备的Mac地址
     * @return
     */
    public String getDeviceMac() {
        return  configSP.getString(KEY_DEVICE_MAC, null);
    }
}
